package com.wu.ssm.service.impl;

import com.wu.ssm.spring.annotion.CacheClear;
import com.wu.ssm.spring.annotion.CachePut;
import com.wu.ssm.spring.annotion.MyService;
import com.wu.ssm.spring.annotion.MyTransactional;
import com.wu.ssm.entity.Custmoer;
import com.wu.ssm.service.CustmoerService;
import com.wu.ssm.spring.utils.JDBCUtils;
import org.springframework.cache.annotation.CacheEvict;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by wzf on 2018/12/4/004.
 */
@MyService
public class CustmoerServiceImpl implements CustmoerService {

    /**
     * 获取客户列表
     */
    @MyTransactional
    @CachePut(value="customer_list_cache")
    public List<Custmoer> getCustmoerList(){
        List<Custmoer> custmoerList = new ArrayList<>();
        String sql = "select * from custmoer";
        custmoerList = JDBCUtils.queryEntityList(Custmoer.class, sql, null);
        return custmoerList;
    }


    /**
     * 清除cache
     */
    @CacheClear(value="customer_list_cache")
    public List<Custmoer> CacheClear(){
        return null;
    }

    /**
     * 创建用户
     */
    @MyTransactional
    public boolean createCustmoer(){
        Map<String, Object> fieldMap = new HashMap<>();
        fieldMap.put("name", "lisi");
        JDBCUtils.insertEntity(Custmoer.class, fieldMap);
        System.out.println(1/0);
        return true;
    }

    /**
     * 删除用户
     */
    public boolean deleteCustmoer(){
        return true;
    }

}
